import MannageService.Manage;
import UserService.User;
import UserService.UserDaoImp;
import userInfo.UserInfoDaoimp;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet(name="PayServlet",value = "/PayServlet")
public class PayServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        resp.setCharacterEncoding("utf-8");
        resp.setHeader("Content-Type","text/html;charset=utf-8");
        String username = req.getParameter("username");//获取用户名
        String phone = req.getParameter("phone");//手机号
        String address = req.getParameter("address");//收货地址
        String psinfo = req.getParameter("psinfo");//备注信息

        String aRightButton = req.getParameter("ArightButton");//确认按钮
        HttpSession session = req.getSession();
        System.out.println("11");
//        String error = "    ";//提示信息

        //用户按下确认按钮
        if (aRightButton != null) {
            if (username == null || username.isEmpty()||phone==null||phone.isEmpty()||address.isEmpty()||address==null) {//判断用户名是否为空
//                error = "收货信息不得有空!请输入!";
//                req.setAttribute("error", error);
                req.getRequestDispatcher("Pay.jsp").forward(req, resp);//重定向,返回收货信息确认界面
            } else {
                System.out.println(username);
                System.out.println(phone);
                System.out.println(address);

                UserInfoDaoimp u = new UserInfoDaoimp();//创建个类
                User user= (User) session.getAttribute("user");//获取服务器存储的用户名字
                u.createInfo(username, phone, address, psinfo, user.getUname());//创建方法进行创建
                System.out.println("插入成功");
                req.getRequestDispatcher("Payways.jsp").forward(req, resp);
            }
        }
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("over");
    }
}